from rest_framework import serializers
from apps.goods.models import  *

# 规格表的序列化器：
class SpecModelSerializer(serializers.ModelSerializer):
    spu = serializers.StringRelatedField()  # 前端需要名字
    spu_id = serializers.IntegerField()   # 默认只能序列化，不能反序列化，显示定义两个都能使用
    class Meta:
        model = SPUSpecification
        fields = ["id", "name", "spu", "spu_id"]


# 规格选项表的序列化器
class OptionModelSerializer(serializers.ModelSerializer):
    spec = serializers.StringRelatedField()
    spec_id = serializers.IntegerField()

    class Meta:
        model = SpecificationOption
        fields = ['id', 'value', 'spec', 'spec_id']


# 规格序列化器
class OptSpecSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = SPUSpecification
        fields = [
            'id',
            'name'
        ]